package com.fei.wechat.middlewar.service.impl.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.fei.wechat.common.constant.EnumConstant.DeleteFlag;
import com.fei.wechat.common.util.ObjectUtils;
import com.fei.wechat.middlewar.api.admin.IOrgaService;
import com.fei.wechat.middlewar.dao.admin.IOrgaDao;
import com.fei.wechat.middlewar.mode.bo.admin.OrgaBo;
import com.fei.wechat.middlewar.mode.entity.admin.Orga;

/**
 * 描述: 机构业务接口实现层
 * 版权: Copyright (c) 2018 
 * 公司: 飞翔科技 
 * 作者: 张进飞 
 * 版本: 1.0 
 * 创建日期: 2018年5月20日 
 * 创建时间: 下午2:04:34
 */
public class OrgaServiceImpl implements IOrgaService
{
    
    @Autowired
    private IOrgaDao orgaDao;
    
    @Override
    public Orga queryOrgaById(Long id)
    {
        Orga orga = orgaDao.queryOrgaById(id);
        return orga;
    }
    
    @Override
    public List<Orga> queryOrgaByIds(List<Long> ids)
    {
        if (null == ids || ids.size() == 0)
        {
            return null;
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        List<Orga> list = orgaDao.queryOrgaByParams(params);
        return list;
    }
    
    @Override
    public List<Orga> queryOrgaList()
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("deleteFlag", DeleteFlag._1.getFalg());
        List<Orga> list = orgaDao.queryOrgaByParams(map);
        return list;
    }
    
    @Override
    public List<Orga> listOrgTree()
    {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("deleteFlag", DeleteFlag._1.getFalg());
        List<Orga> orgList = orgaDao.queryOrgaByParams(map);
        return orgList;
    }
    
    @Override
    public void saveOrga(OrgaBo orgaBo) throws Exception
    {
        if (null == orgaBo)
        {
            return;
        }
        Map<String, Object> params = ObjectUtils.objectToMap(orgaBo);
        this.orgaDao.saveOrga(params);
    }
    
    @Override
    public void updateOrga(OrgaBo orgaBo) throws Exception
    {
        if (null == orgaBo || null == orgaBo.getId())
        {
            return;
        }
        Map<String, Object> params = ObjectUtils.objectToMap(orgaBo);
        if (!params.containsKey("sortNum") || null == params.get("sortNum"))
        {
            params.put("sortNumIsNull", 1);
        }
        if (!params.containsKey("remark") || null == params.get("remark"))
        {
            params.put("remarkIsNull", 1);
        }
        this.orgaDao.updateOrga(params);
    }
    
    @Override
    public void removeOrga(List<Long> ids) throws Exception
    {
        if (null == ids || ids.isEmpty())
        {
            return;
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("ids", ids);
        this.orgaDao.batchDeleteOrga(params);
    }
    
}
